package com.ruoyi.web.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SetModel;
import com.ruoyi.system.domain.client.MesClientPages;
import com.ruoyi.system.service.IMesClientPagesService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端页面Controller
 *
 * @author ruoyi
 * @date 2023-02-20
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/client/mes_client_pages" )
public class MesClientPagesController extends BaseController {

    private final IMesClientPagesService iMesClientPagesService;

    /**
     * 查询客户端页面列表
     */
    @ApiOperation(value = "查询table页面")
    @GetMapping("/list")
    public TableDataInfo list(MesClientPages mesClientPages)
    {
        startPage();
        LambdaQueryWrapper<MesClientPages> lqw = new LambdaQueryWrapper<MesClientPages>();
        if (StringUtils.isNotBlank(mesClientPages.getPageCode())){
            lqw.like(MesClientPages::getPageCode ,mesClientPages.getPageCode());
        }
        if (StringUtils.isNotBlank(mesClientPages.getPageName())){
            lqw.like(MesClientPages::getPageName ,mesClientPages.getPageName());
        }
        if (StringUtils.isNotBlank(mesClientPages.getStatus())){
            lqw.eq(MesClientPages::getStatus ,mesClientPages.getStatus());
        }
        List<MesClientPages> list = iMesClientPagesService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 查询客户端页面列表
     */
    @ApiOperation(value = "查询页面下拉接口")
    @GetMapping("/allList")
    public AjaxResult allList(MesClientPages mesClientPages)
    {
        List<MesClientPages> list = iMesClientPagesService.selectMesClientPageslList(mesClientPages);
        return AjaxResult.success(list);
    }

    /**
     * 导出客户端页面列表
     */
    @Log(title = "客户端页面" , businessType = BusinessType.EXPORT)
    @ApiOperation(value = "客户端页面导出")
    @GetMapping("/export" )
    public AjaxResult export(MesClientPages mesClientPages) {
        LambdaQueryWrapper<MesClientPages> lqw = new LambdaQueryWrapper<MesClientPages>(mesClientPages);
        List<MesClientPages> list = iMesClientPagesService.list(lqw);
        ExcelUtil<MesClientPages> util = new ExcelUtil<MesClientPages>(MesClientPages. class);
        return util.exportExcel(list, "mes_client_pages" );
    }

    /**
     * 获取客户端页面详细信息
     */
    @GetMapping(value = "/{pageId}" )
    @ApiOperation(value = "获取客户端页面")
    public AjaxResult getInfo(@PathVariable("pageId" ) Long pageId) {
        return AjaxResult.success(iMesClientPagesService.getById(pageId));
    }

    /**
     * 新增客户端页面
     */
    @Log(title = "客户端页面" , businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增客户端页面")
    @PostMapping
    public AjaxResult add(@RequestBody MesClientPages mesClientPages) {
        return toAjax(iMesClientPagesService.save(mesClientPages) ? 1 : 0);
    }

    /**
     * 修改客户端页面
     */
    @Log(title = "客户端页面" , businessType = BusinessType.UPDATE)
    @ApiOperation(value = "编辑客户端页面")
    @PutMapping
    public AjaxResult edit(@RequestBody MesClientPages mesClientPages) {
        return toAjax(iMesClientPagesService.updateById(mesClientPages) ? 1 : 0);
    }

    /**
     * 删除客户端页面
     */
    @Log(title = "客户端页面" , businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除客户端页面")
    @DeleteMapping("/{pageIds}" )
    public AjaxResult remove(@PathVariable Long[] pageIds) {
        return toAjax(iMesClientPagesService.removeByIds(Arrays.asList(pageIds)) ? 1 : 0);
    }
}
